<template>
	<div>
		<el-form ref="form" :model="form" :rules="rules" label-width="80px">
			<el-row>
				<el-col span="10">
					<el-form-item label="姓名"  prop="customerName">
						<el-input v-model="form.customerName"></el-input>
					</el-form-item>
				</el-col>
				
				<el-col span="10">
					<el-form-item label="性别" prop="customerGender" label-width="120px">
						<el-select v-model="form.customerGender" placeholder="请选择..">
							<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
			
			<el-row>
				<el-col span="10">
					<el-form-item label="年龄" prop="customerAge">
						<el-input v-model="form.customerAge"></el-input>
					</el-form-item>
				</el-col>
				
				<el-col span="10">
					<el-form-item label="档案编号" prop="recordId" label-width="120px">
						<el-input v-model="form.recordId"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			
			<el-row>
				<el-col span="10">
					<el-form-item label="入住时间" prop="checkinDate">
						<el-date-picker value-format="yyyy-MM-dd" type="date" v-model="form.checkinDate" placeholder="选择日期">
						</el-date-picker>
					</el-form-item>
				</el-col>
				
				<el-col span="10">
					<el-form-item label="退住时间" prop="backDate" label-width="120px">
						<el-date-picker value-format="yyyy-MM-dd" type="date" v-model="form.backDate" placeholder="选择日期">
						</el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>
			
			<el-row>
				<el-col span="10">
					<el-form-item label="退住类型">
						<el-input v-model="form.backType"></el-input>
					</el-form-item>
				</el-col>
				
				<el-col span="10">
					<el-form-item label="退住原因" label-width="120px">
						<el-input v-model="form.backCause"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			
			
			<el-row>
				<el-col span="10">
					<el-form-item label="状态">
						<el-input v-model="form.status"></el-input>
					</el-form-item>
				</el-col>
				
				<el-col span="10">
					<el-form-item label="申请时间" prop="applyDate" label-width="120px">
						<el-date-picker value-format="yyyy-MM-dd" type="date" v-model="form.applyDate" placeholder="选择日期">
						</el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>
			
			<el-row>
				<el-col span="10">
					<el-form-item label="审核意见" prop="auditView">
						<el-input v-model="form.auditView"></el-input>
					</el-form-item>
				</el-col>
				
				<el-col span="10">
					<el-form-item label="审核人" prop="auditPerson" label-width="120px">
						<el-input v-model="form.auditPerson"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			
			
			<el-row>
				<el-col span="10">
					<el-form-item label="审核时间" prop="auditDate">
						<el-date-picker value-format="yyyy-MM-dd" type="date" v-model="form.auditDate" placeholder="选择日期">
						</el-date-picker>
					</el-form-item>
				</el-col>
				
				<el-col span="10">
					<el-form-item label="备注" label-width="120px">
						<el-input v-model="form.remarks"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row></el-row>
			<el-row></el-row>
			<el-form-item>
				<el-button type="primary" plain @click="save">保存数据</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import axios from '@/utils/axiosutils.js';
	export default {
		name: 'BackAdd',
		props: ['editid'],
		components: {},
		data() {
			return {
				form: {
					customerName: '',
					customerGender: '',
					customerAge: '',
					recordId: '',
					checkinDate: '',
					backDate: '',
					backType: '',
					backCause: '',
					status: '',
					applyDate: '',
					auditView: '',
					auditPerson: '',
					auditDate: '',
					remarks: ''
				},
				rules:{
					customerName:[{required: true, message: '请输入', trigger: 'blur'}],
					customerGender:[{required: true, message: '请输入', trigger: 'blur'}],
					customerAge:[{required: true, message: '请输入', trigger: 'blur'}],
					recordId:[{required: true, message: '请输入', trigger: 'blur'}],
					checkinDate:[{required: true, message: '请输入', trigger: 'blur'}],
					backDate:[{required: true, message: '请输入', trigger: 'blur'}],
					applyDate:[{required: true, message: '请输入', trigger: 'blur'}],
					auditView:[{required: true, message: '请输入', trigger: 'blur'}],
					auditPerson:[{required: true, message: '请输入', trigger: 'blur'}],
					auditDate:[{required: true, message: '请输入', trigger: 'blur'}],
					
				},
				isupdate: false,
				 options: [{
				          value: '男',
				          label: '男'
				        }, {
				          value: '女',
				          label: '女'
				        }]
			};
		},
		created() {
			if (this.editid) {
				// 如果是修改 用户名输入框禁用
				this.isupdate = true;
				axios.get(
					'/back/getById',
					response => {
						this.form.backId = this.editid;
						this.form.customerName = response.obj.customerName;
						this.form.customerGender = response.obj.customerGender;
						this.form.customerAge = response.obj.customerAge;
						this.form.recordId = response.obj.recordId;
						this.form.checkinDate = response.obj.checkinDate;
						this.form.backDate = response.obj.backDate;
						this.form.backType = response.obj.backType;
						this.form.backCause = response.obj.backCause;
						this.form.status = response.obj.status;
						this.form.applyDate = response.obj.applyDate;
						this.form.auditView = response.obj.auditView;
						this.form.auditPerson = response.obj.auditPerson;
						this.form.auditDate = response.obj.auditDate;
						this.form.remarks = response.obj.remarks;
					}, {
						backId: this.editid
					}
				);
			}
		},
		methods: {
			save: function() {
				axios.post(
					'/back/add',
					resp => {
						this.$emit('update:show', false);
						this.$emit('getData');
					},
					this.form
				);
			}
		}
	};
</script>

<style scoped>
	.el-row{
		height: 60px;
	}
</style>
